import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/getParameter")
public class GetParameterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 这里约定,程序中给出的query string 是usename=zhangsan & password=123
        // 上述query sting 会自动被tomcat解析为Map<String,String> 这样的结构
        // getParameter 就是在查询 Map<Sting,String> 里的内容
        String usename = req.getParameter("usename");
        String password = req.getParameter("password");
        // 就可以拿到这两内容做一些其他的处理了
        System.out.println("usename = " + usename);
        System.out.println("password = " + password);

        resp.getWriter().write("ok");
    }
}
